'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:TaskMytasklistCtrl
 * @description
 * # TaskMytasklistCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('TaskMytasklistCtrl', function(openApi, DataService, $location, $routeParams) {
        this.pageOpt = {
            "curpage": 1,
            "limit": 10
        }
        this.getPageType = function(type) {
            var title;
            type = parseInt(type, 10)
            switch (type) {
                case 1:
                case 5:
                case 9:
                    title = "我负责的任务";
                    break;
                case 2:
                case 6:
                case 10:
                    title = "我参与的任务";
                    break;
                case 3:
                case 7:
                case 11:
                    title = "可查阅的任务";
                    break;
                case 4:
                case 8:
                case 12:
                    title = "我创建的任务";
                    break;
            }
            return title
        };
        this.title = this.getPageType($routeParams.pagetype)
        this.initData = function() {
            var param = {}
            param.flag = parseInt($routeParams.pagetype, 10)
            param.limit = this.pageOpt.limit;
            param.start = (this.pageOpt.curpage - 1) * this.pageOpt.limit
            DataService.getData(openApi.getMyTaskbypage, param).then(function(data) {
                if (data&&data.length < 1||data&&data.length < this.pageOpt.limit) {
                    this.shownext = false
                } else {
                    this.shownext = true
                }
                this.datalist = data
            }.bind(this))

        };
        this.initData();
        this.goDetail = function(item) {
            var param = {}
            param.refId = item.pkId;
            DataService.getData(openApi.hasSeenByWorktask, param).then(function(data) {
                console.log(data)
            }.bind(this))
            $location.path("task/taskdetail/" + item.pkId)
        }
        this.prevpage = function() {
            this.pageOpt.curpage--
                this.initData()
        }
        this.nextpage = function() {
            this.pageOpt.curpage++
                this.initData()
        }
        this.firstpage = function() {
            this.pageOpt.curpage = 1
            this.initData()
        }
    });
